home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Cafe 3
/
Visual Cafe 3.ISO
/
Vcafe
/
Main.bin
/
CustomOverrideSupport.java
< prev
next >
Wrap
Text File
|
1998-09-23
|
4KB
|
118 lines
package com.symantec.itools.vcafe.beans;
import java.io.Serializable;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
/**
* This is a utility class that can be used by customizers that implement
* it's own OK/Cancel buttons. You can use an instance of this class as a
* member field of your bean and delegate various work to it.
*/
public class CustomOverrideSupport implements java.io.Serializable {
/**
* @param customizer The customizer.
*/
public CustomOverrideSupport(Object customizer) {
this.customizer = customizer;
}
/**
* Add a CustomOverrideListener to the listener list.
*
* @param listener The CustomOverrideListener to be added
*/
public synchronized void addCustomOverrideListener(CustomOverrideListener listener) {
if (listeners == null) {
listeners = new java.util.Vector();
}
listeners.addElement(listener);
}
/**
* Remove a CustomOverrideListener from the listener list.
*
* @param listener The CustomOverrideListener to be removed
*/
public synchronized void removeCustomOverrideListener(CustomOverrideListener listener) {
if (listeners == null) {
return;
}
listeners.removeElement(listener);
}
/**
* Report a bound property update to any registered listeners.
* No event is fired if old and new are equal and non-null.
*
* @param state CustomOverrideEvent.CUSTOMIZER_OK or
* CustomOverrideEvent.CUSTOMIZER_CANCEL
*/
public void fireCustomOverride(int state) {
java.util.Vector targets;
synchronized (this) {
if (listeners == null) {
return;
}
targets = (java.util.Vector) listeners.clone();
}
CustomOverrideEvent evt = new CustomOverrideEvent(customizer, state);
if (state == CustomOverrideEvent.CUSTOMIZER_OK) {
for (int i = 0; i < targets.size(); i++) {
CustomOverrideListener target = (CustomOverrideListener)targets.elementAt(i);
target.okPressed(evt);
}
} else if (state == CustomOverrideEvent.CUSTOMIZER_CANCEL) {
for (int i = 0; i < targets.size(); i++) {
CustomOverrideListener target = (CustomOverrideListener)targets.elementAt(i);
target.cancelPressed(evt);
}
}
}
private void writeObject(ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
java.util.Vector v = null;
synchronized (this) {
if (listeners != null) {
v = (java.util.Vector) listeners.clone();
}
}
if (v != null) {
for(int i = 0; i < v.size(); i++) {
CustomOverrideListener l = (CustomOverrideListener)v.elementAt(i);
if (l instanceof Serializable) {
s.writeObject(l);
}
}
}
s.writeObject(null);
}
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
s.defaultReadObject();
Object listenerOrNull;
while(null != (listenerOrNull = s.readObject())) {
addCustomOverrideListener((CustomOverrideListener)listenerOrNull);
}
}
transient private java.util.Vector listeners;
private Object customizer;
private int customzierChangeSupportSerializedDataVersion = 1;
}